package cn.git.demo.controller.order;



import cn.git.demo.pojo.OrderDetail;
import cn.git.demo.pojo.User;
import cn.git.demo.service.OrderDetailService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;


@Controller
@Transactional
public class OrderDetailController {

    @Autowired
    private OrderDetailService orderDetailService;
    @RequestMapping(value = "order/orderDetail.do")
    public String orderDetail(Long oid,Model model) {

        List<OrderDetail> orderDetails = orderDetailService.selectDetailListByOid(oid);

        model.addAttribute(orderDetails);

        return "order/detail";
    }
    @RequestMapping(value = "/orderDetail/insert.do")
    public String insert(Long[] ids,String[] names,Long id,Integer[] pno){

        List<OrderDetail> list = new ArrayList<OrderDetail>();

        for (int i=0;i<ids.length;i++){
            OrderDetail orderDetail = new OrderDetail();
            orderDetail.setDid(ids[i]);
            orderDetail.setOid(id);
            orderDetail.setPname(names[i]);
            orderDetail.setPno(pno[i]);
            list.add(orderDetail);
        }
        orderDetailService.addOrderDetails(list);

        return "redirect:/order/list.do";
    }
}